<template>
  <div class="tab-bar-item" @click="itemClick" :style="styleColor">
    <slot name="item-icon" v-if="!isActive"></slot>
    <slot name="item-icon-active" v-else></slot>
    <slot name="item-text"></slot>
  </div>
</template>

<script>
  export default {
    name: 'TabBarItem',
    props: {
      to: { type: String, required: true },
      activeColor: { type: String, default: 'red' }
    },
    computed: {
      isActive() {
        return this.$route.path.indexOf(this.to) !== -1
      },
      styleColor() {
        return this.isActive ? { color: this.activeColor } : {}
      }
    },
    methods: {
      itemClick() {
        this.$router.push(this.to)
      }
    }
  }
</script>

<style scoped>
  .tab-bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .tab-bar-item img {
    width: 24px;
  }
</style>
